package org.xdq.可重入锁;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class 练习 {

    static int j=0;

    public static void main(String[] args) {

        Lock lock = new ReentrantLock();

        for(int i=0;i<2;i++){
            new Thread(){
                @Override
                public void run() {
                   lock.lock();
                    try {
                        j++;
                    } finally {
                        lock.unlock();
                    }

                }
            }.start();

            new Thread(){
                @Override
                public void run() {

                    lock.lock();
                    try {
                        j--;
                    } finally {
                        lock.unlock();
                    }

                }
            }.start();
        }

    }
}
